package cateServe

import (
	catemodel "forum/app/model/cateModel"
	cateData "forum/app/structData/cate"
	"forum/app/tools"
)

func GetList(keyWord string) []map[string]interface{} {
	list := catemodel.GetList(keyWord)
	result := make([]map[string]interface{}, len(list))
	for i, item := range list {
		result[i] = map[string]interface{}{
			"id":           item.Id,
			"title":        item.Title,
			"pid":          item.Pid,
			"sort":         item.Sort,
			"status":       item.Status,
			"created_time": tools.GetDate(item.CreatedTime),
			"updated_time": tools.GetDate(item.UpdatedTime),
		}
	}
	return result
}

func Create(params cateData.CreateRequest) int64 {
	if params.Title == "" {
		panic("分类名称不能为空")
	}
	id := catemodel.Create(params)
	return id
}
